package com.tg.service.base.factorybean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class MyBeanAFactoryBean implements FactoryBean<MyBeanA>, ApplicationContextAware {

    private ApplicationContext context;

    @Override
    public MyBeanA getObject() throws Exception {
        MyService myService = (MyService) this.context.getBean("MyService");
        MyBeanA myBeanA = new MyBeanA();
        myBeanA.setMyService(myService);
        return myBeanA;
    }

    @Override
    public Class<?> getObjectType() {
        return MyBeanA.class;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
